package LinkedList;
class ListNode3 {
    int val;
    ListNode3 next;
    ListNode3() {
    }
    ListNode3(int val) {
        this.val = val;
    }
    ListNode3(int val, ListNode3 next) {
        this.val = val;
        this.next = next;
    }
}
//利用快慢指针，求倒数第k个节点
class Solution4 {
    public ListNode3 reciprocalNode(ListNode3 head,int k,int size) {
        if(k<1||k>size){
            return null;
        }
        if(head==null){
            return head;
        }
        ListNode3 fast = head;
        ListNode3 slow = head;
        for(int i =1;i<k;i++){
            fast = fast.next;
        }
        while (fast.next!=null){
            fast = fast.next;
            slow = slow.next;
        }
        return slow;
    }
}
